function init(config) {
  return {
    getMyGroupInfo() {
      const url = `${config.pre}/crowd/info/${Cookies.get('areaCode')}/owner`
      const opt = {
        method: 'GET',
        headers: {
          Authorization: Cookies.get('token')
        }
      }
      return fetch(url, opt)
    },
    getRuleList(params) {
      const query = queryString.stringify(params)
      const url = `${config.pre}/crowd/conf/${Cookies.get('areaCode')}?${query}`
      const opt = {
        method: 'GET',
        headers: {
          Authorization: Cookies.get('token')
        }
      }
      return fetch(url, opt)
    },
    getRuleMemberList(params) {
      const query = queryString.stringify(params)
      const url = `${config.pre}/crowd/user/${Cookies.get('areaCode')}?${query}`
      const opt = {
        method: 'GET',
        headers: {
          Authorization: Cookies.get('token')
        }
      }
      return fetch(url, opt)
    },
    createRule(send) {
      const url = `${config.pre}/crowd/conf/${Cookies.get('areaCode')}`
      const sendObj = Object.assign({}, send)
      sendObj.jsonContent = JSON.stringify(sendObj.jsonContent)
      console.log(sendObj);
      const opt = {
        method: 'POST',
        body: JSON.stringify(sendObj),
        headers: {
          Authorization: Cookies.get('token'),
          'Content-type': 'application/json'
        }
      }
      return fetch(url, opt)
    },
    deleteRuleMember(id) {
      const url = `${config.pre}/crowd/user/${Cookies.get('areaCode')}/${id}`
      const opt = {
        method: 'DELETE',
        headers: {
          Authorization: Cookies.get('token'),
          'Content-type': 'application/json'
        }
      }
      return fetch(url, opt)
    },
    modGroupInfo(send) {
      const temp = Object.assign({}, send)
      temp.jsonContent = JSON.stringify(temp.jsonContent)
      console.log('mod', temp);
      const url = `${config.pre}/crowd/info/${Cookies.get('areaCode')}`
      const opt = {
        method: 'PUT',
        body: JSON.stringify(temp),
        headers: {
          Authorization: Cookies.get('token'),
          'Content-type': 'application/json'
        }
      }
      return fetch(url, opt)
    },
    modGroupConf(send) {
      const temp = Object.assign({}, send)
      temp.jsonContent = JSON.stringify(temp.jsonContent)
      console.log('mod', temp);
      const url = `${config.pre}/crowd/conf/${Cookies.get('areaCode')}`
      const opt = {
        method: 'PUT',
        body: JSON.stringify(temp),
        headers: {
          Authorization: Cookies.get('token'),
          'Content-type': 'application/json'
        }
      }
      return fetch(url, opt)
    },
    deleteRule(id) {
      const url = `${config.pre}/crowd/conf/${Cookies.get('areaCode')}/${id}`
      const opt = {
        method: 'DELETE',
        headers: {
          Authorization: Cookies.get('token')
        }
      }
      return fetch(url, opt)
    },
    deleteGroup(id) {
      const url = `${config.pre}/crowd/info/${Cookies.get('areaCode')}/${id}`
      const opt = {
        method: 'DELETE',
        headers: {
          Authorization: Cookies.get('token')
        }
      }
      return fetch(url, opt)
    },
    getApplyList(params) {
      const query = queryString.stringify(params)
      const url = `${config.pre}/crowd/apply/${Cookies.get('areaCode')}?${query}`
      const opt = {
        method: 'GET',
        headers: {
          Authorization: Cookies.get('token')
        }
      }
      return fetch(url, opt)
    },
    auditApply(params) {
      console.log('params', params);
      const url = `${config.pre}/crowd/apply/${Cookies.get('areaCode')}`
      const opt = {
        method: 'PUT',
        body: JSON.stringify(params),
        headers: {
          Authorization: Cookies.get('token'),
          'Content-type': 'application/json'
        }
      }
      return fetch(url, opt)
    },
    invitePlayer(params) {
      const url = `${config.pre}/crowd/user/${Cookies.get('areaCode')}`
      const opt = {
        method: 'POST',
        body: JSON.stringify(params),
        headers: {
          Authorization: Cookies.get('token'),
          'Content-type': 'application/json'
        }
      }
      return fetch(url, opt)
    },
    getGameRecord(params) {
      const url = `${config.pre}/grouprecord/${Cookies.get('areaCode')}/${params.recordType}/${params.offset}/${params.limit}`
      const opt = {
        method: 'GET',
        headers: {
          Authorization: Cookies.get('token')
        }
      }
      return fetch(url, opt)
    },
    getUploadPicUrl() {
      return `${config.pre}/media/image/fileUpload/${Cookies.get('areaCode')}`
    }
  }
}

export default init